//===============================================================================
// Microsoft patterns & practices
// Smart Client Software Factory 2010
//===============================================================================
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
//----------------------------------------------------------------------------------------
// patterns & practices - Smart Client Software Factory - Guidance Package
//
// This file was generated by the "Add Business Module" recipe.
//
// This class contains placeholder methods for the common module initialization 
// tasks, such as adding services, or user-interface element
//
// For more information see: 
// ms-help://MS.VSCC.v90/MS.VSIPCC.v90/ms.practices.scsf.2008apr/SCSF/html/02-08-060-Add_Business_Module_Next_Steps.htm
//
// Latest version of this Guidance Package: http://go.microsoft.com/fwlink/?LinkId=62182
//----------------------------------------------------------------------------------------

using System;
using System.Windows.Forms;
using QuickStart.Infrastructure.Interface;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.Commands;
using QuickStart.RestaurantModule.Constants;
using QuickStart.RestaurantModule.DSA.MenuServiceClient;
using Microsoft.Practices.CompositeUI.EventBroker;

namespace QuickStart.RestaurantModule
{
    public class ModuleController : WorkItemController
    {
        ToolStripProgressBar _progressBar;

        public override void Run()
        {
            AddServices();
            ExtendStatusStrip();
            AddViews();
        }

        private void AddServices()
        {
            WorkItem.Services.AddNew<Agent>();
        }

        private void ExtendStatusStrip()
        {
            UIExtensionSite status = WorkItem.UIExtensionSites[UIExtensionSiteNames.MainStatus];
            _progressBar = new ToolStripProgressBar();
            _progressBar.Style = ProgressBarStyle.Marquee;
            _progressBar.Visible = false;
            status.Add(_progressBar);
        }

        private void AddViews()
        {
            ShowViewInWorkspace<MenuItemsView>(WorkspaceNames.RightWorkspace);
            ShowViewInWorkspace<RestaurantsView>(WorkspaceNames.LeftWorkspace);
        }

        [EventSubscription(EventTopicNames.LongProcess, ThreadOption.UserInterface)]
        public void OnLongProcessStarted(object sender, EventArgs<bool> eventArgs)
        {
            Cursor.Current = eventArgs.Data ? Cursors.WaitCursor : Cursors.Default;
            _progressBar.Visible = eventArgs.Data;
        }
    }
}
